package cn.qyl.joha.dao.Impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import cn.qyl.joha.common.PageModel;
import cn.qyl.joha.dao.BaseDao;
import cn.qyl.joha.dao.OrderDao;
import cn.qyl.joha.dto.Order;
import cn.qyl.joha.mapper.OrderMapper;

public class OrderDaoImpl extends BaseDao implements OrderDao {

	@Override
	public int getCountByOrder(Order order) {
		SqlSession session = getSqlSession();
		OrderMapper orderMapper = session.getMapper(OrderMapper.class);
		//获取总数量
		int count = orderMapper.getCountByOrder(order);
		//释放资源
		closeSqlSession();
		return count;
	}

	@Override
	public List<Order> getOrdersByPage(Order order, PageModel pageModel) {
		SqlSession session = getSqlSession();
		OrderMapper orderMapper = session.getMapper(OrderMapper.class);
		List<Order> orders = orderMapper.getOrdersByPage(order,pageModel);
		//释放资源
		closeSqlSession();
		return orders;
	}
	
	//新增订单
	@Override
	public int addOrders(Order order) {
		//获取SqlSession
		SqlSession session = getSqlSession();
		//获取数据访问接口文件对象、
		OrderMapper orderMapper = session.getMapper(OrderMapper.class);
		int count = orderMapper.addOrders(order);
		//提交事务
		session.commit();
		//释放资源
		closeSqlSession();
		
		return count;
		
	}
	

}
